const { Sequelize, DataTypes } = require("sequelize");
const sequelize = require('.')
const City = sequelize.define(
  "City",
  {
    id: {
      type: Sequelize.INTEGER,
      primaryKey: true,
      autoIncrement: true,
    },
    name: {
      type: DataTypes.STRING,
      defaultValue: null,
    },
  },
  {
    timestamps: false,
  }
);

// const createTable = (sequelize) => {

//   return sequelize;
// };
async function deleteAll() {
  await City.destroy({
    where: {},
    truncate: true,
  });
}
async function create(params) {
  const city = [
    { id: 1, name: "常州" },
    { id: 2, name: "上海" },
    { id: 3, name: "南京" },
    { id: 4, name: "滁州" },
    { id: 5, name: "无锡" },
    { id: 6, name: "苏州" },
    { id: 7, name: "南通" },
    { id: 8, name: "镇江" },
    { id: 9, name: "杭州" },
    { id: 10, name: "宁波" },
  ];
  for (let i of city) {
    City.create({
      id: i.id,
      name: i.name,
    });
  }
}
(async () => {
  await City.sync(); // Creates the table if it doesn't exist
  // await deleteAll();
  await create()
})();

module.exports = City